package com.gcb.controller.order;

import com.gcb.common.annotation.Log;
import com.gcb.controller.BaseController;
import com.gcb.common.core.domain.AjaxResult;
import com.gcb.common.core.page.TableDataInfo;
import com.gcb.common.enums.BusinessType;
import com.gcb.common.utils.poi.ExcelUtil;
import com.gcb.domain.dto.OrderStaffQueryDTO;
import com.gcb.domain.dto.OrderStaffSaveDTO;
import com.gcb.domain.vo.OrderStaffVO;
import com.gcb.service.IOrderStaffService;
import com.gcb.framework.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/orderStaff")
@Tag(name = "后台求职订单管理", description = "后台求职订单管理")
public class OrderStaffController extends BaseController {

    @Resource
    private IOrderStaffService orderStaffService;

    /**
     * 新增求职订单
     *
     * @param dto
     * @return
     */
    @PreAuthorize("@ss.hasPermi('order:orderStaff:add')")
    @PostMapping("/add")
    @Operation(summary = "502.发布求职订单")
    public AjaxResult add(@RequestBody OrderStaffSaveDTO dto) {
        orderStaffService.add(dto, SecurityUtils.getUserId());
        return success();
    }

    /**
     * 编辑求职订单
     *
     * @param dto
     * @return
     */
    @PreAuthorize("@ss.hasPermi('order:orderStaff:update')")
    @PostMapping("/update")
    @Operation(summary = "503.编辑求职订单 ")
    public AjaxResult update(@RequestBody OrderStaffSaveDTO dto) {
        orderStaffService.update(dto, SecurityUtils.getUserId());
        return success();
    }

    /**
     * 求职订单列表接口
     *
     * @param queryDTO
     * @return
     */
    @PreAuthorize("@ss.hasPermi('order:orderStaff:list')")
    @GetMapping("/pageList")
    @Operation(summary = "501.求职订单列表接口")
    public TableDataInfo list(OrderStaffQueryDTO queryDTO) {
        startPage();
        List<OrderStaffVO> list = orderStaffService.list(queryDTO);
        return getDataTable(list);
    }

    /**
     * 求职订单详情接口
     *
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('order:orderStaff:getDetail')")
    @GetMapping("/getDetail")
    @Operation(summary = "506.求职订单详情接口")
    public AjaxResult detail(Long id) {
        OrderStaffVO vo = orderStaffService.getDetail(id);
        return success(vo);
    }

    /**
     * 批量暂停/恢复/结束接口
     *
     * @param ids
     * @param state
     * @return
     */
    @PreAuthorize("@ss.hasPermi('order:orderStaff:batchUpdateState')")
    @GetMapping("/batchUpdateState")
    @Operation(summary = "505.批量暂停/恢复/结束接口")
    public AjaxResult batchUpdateState(Long[] ids, Integer state) {
        orderStaffService.batchUpdateState(ids, state, SecurityUtils.getUserId());
        return success();
    }

    /**
     * 导出求职订单
     */
    @PreAuthorize("@ss.hasPermi('order:orderStaff:export')")
    @Log(title = "导出求职订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "504.导出求职订单")
    public void export(HttpServletResponse response, OrderStaffQueryDTO queryDTO) {
        List<OrderStaffVO> list = orderStaffService.list(queryDTO);
        ExcelUtil<OrderStaffVO> util = new ExcelUtil<>(OrderStaffVO.class);
        util.exportExcel(response, list, "导出求职订单");
    }
}
